package org.effdom.util;

/**
 * @author <a href="mailto:mattias@effcode.com">Mattias Jonsson</a>
 */
public class Hex {

    private static final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    public static final String toHex(final byte[] value) {
        char buf[] = new char[value.length * 2];
        for (int i = 0, x = 0; i < value.length; i++) {
            buf[x++] = HEX_CHARS[(value[i] >>> 4) & 0xf];
            buf[x++] = HEX_CHARS[value[i] & 0xf];
        }
        return new String(buf);
    }
}
